var express = require('express');
var router = express.Router();
var fs = require('fs')
var multiparty = require('multiparty');
var xlsx = require("node-xlsx").default;
const jwt = require('jsonwebtoken');
const { TypeModel, BusinessModel, GoodModel,UserModule,shopModel } = require('../mongodb/db.js')
// const express = require("express");
const multer = require('multer');
const path = require("path")

// 获取店铺
router.get('/getShop', async (req, res) => {
    // 排序
    let condition = {}
    if(req.query.distance&&req.query.distance!=''){
        condition.distance=1
    }
    if(req.query.time&&req.query.time!=''){
        condition.time=1
    }
    
    
    if(req.query.num1&&req.query.num1!=''){
        condition.num=1
    }
    if(req.query.price&&req.query.price!=''){
        condition.price=1
    }
    console.log(condition);
    
    // 搜索
    let condition1 = {}
    if(req.query.key&&req.query.key!=''){
        condition1.name=req.query.key
    }
    
    if(req.query.type&&req.query.type!='全部'){
        condition1.type=req.query.type
    }

    if(req.query.buy){
        condition1.buy =true
    }

    console.log(condition1);
    let data = await shopModel.find(condition1).sort(condition)

    console.log(data);
    
    if(data.length!=0){
        res.send({code: 200,data: data})
    }else{
        res.send({code: 400,data: "暂无数据"})
    }
    
    // console.log(req.query,data);
})


















module.exports = router;
